package com.handong.handserialprogram.module.createmission;

import android.content.Intent;
import android.os.Bundle;

import com.handong.handserialprogram.R;
import com.handong.handserialprogram.model.entities.FootRingNewEntity;
import com.handong.handserialprogram.model.entities.PersonEntity;
import com.handong.handserialprogram.module.base.BackStackActivity;
import com.handong.handserialprogram.module.base.BaseActivity;
import com.handong.handserialprogram.module.createmission.recordtask.CriminalFragment;
import com.handong.handserialprogram.module.createmission.recordtask.RecordTaskFragment;
import com.handong.handserialprogram.module.createmission.searchring.SearchRingFragment;
import com.handong.handserialprogram.module.serialport.SerialPortUtil;

import java.util.List;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

public class CreateMissionActivity extends BackStackActivity {

    private static final int NEED_SIZE = 4;
    public boolean IsFinish=false;

    public CopyOnWriteArrayList<FootRingNewEntity> getmRingList() {
        return mRingList;
    }

    public SerialPortUtil mSerialPortUtil;

    public void setmRingList(CopyOnWriteArrayList<FootRingNewEntity> mRingList) {
        this.mRingList = mRingList;
    }

    private CopyOnWriteArrayList<FootRingNewEntity> mRingList=new CopyOnWriteArrayList<FootRingNewEntity>();
    @Override
    protected int getContentViewID() {
        return R.layout.activity_create_mission;
    }

    @Override
    protected void initViewDataRes() {
        addFirstFragment(RecordTaskFragment.newInstance(), R.id.createMissionContainer, NEED_SIZE);
    }


    /**
     * 保存犯人
     */
    public void savePersonList(int type) {
        RecordTaskFragment fragment = (RecordTaskFragment) getIndexFragment(0);
        fragment.savePersonList(type);
    }

    /**
     * 保存任务
     */
    public void saveTaskInfo(String content, String idName,boolean isCar) {
        RecordTaskFragment fragment = (RecordTaskFragment) getIndexFragment(0);
        fragment.saveTaskCar(content, idName,isCar);
    }

    public void addSearchPerson(PersonEntity entity){
        CriminalFragment fragment = (CriminalFragment) getIndexFragment(1);
        fragment.addCriminal(entity, true);
    }

//    public void saveEntityList(Vector<FootRingNewEntity> list)
//    {
//        RecordTaskFragment fragment=(RecordTaskFragment)getIndexFragment(0);
//        fragment.saveEntityList(list);
//    }

    public void openActWithFadeOut(Class<? extends BaseActivity> cls, Bundle bundle) {
        Intent intent = new Intent(this, cls);
        intent.putExtras(bundle);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.push_left_in, R.anim.anim_fade_out);
    }
    @Override
    public void onBackPressed() {
        RecordTaskFragment rFragment = (RecordTaskFragment) getIndexFragment(0);
        SearchRingFragment sFragment = new SearchRingFragment();
//        Log.d("12345","isResumed+="+rFragment.isResumed()+"+="+sFragment.isResumed());
//        Log.d("12345","isHidden+="+rFragment.isHidden()+"+="+sFragment.isHidden());
//        Log.d("12345","isDetached+="+rFragment.isDetached()+"+="+sFragment.isDetached());
//        Log.d("12345","isAdded+="+rFragment.isAdded()+"+="+sFragment.isAdded());
//        Log.d("12345","isRemoving+="+rFragment.isRemoving()+"+="+sFragment.isRemoving());
//        Log.d("12345","isVisible+="+rFragment.isVisible()+"+="+sFragment.isVisible());
        if (!rFragment.isHidden()&&!sFragment.isHidden()) {
            rFragment.onBackPressed();
        }
        super.onBackPressed();
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.anim_no, R.anim.push_right_out);
    }
}
